﻿using System;

using DflyingForum.Core.Data.Domain.ValueObjects;
using Iesi.Collections.Generic;

namespace DflyingForum.Core.Data.Domain.Entities
{
    /// <summary>
    /// 定义论坛的用户
    /// </summary>
    public class User : EntityBase
    {
        private  ISet<Group> _groups;
        private  ISet<Posts> _posts;
        private  ISet<Reply> _reply;

        #region 属性

        public virtual string UserName { get; set; }

        public virtual string UserPwd { get; set; }

        public virtual string NickName { get; set; }

        public virtual Name FullName { get; set; }

        public virtual string Email { get; set; }

        /// <summary>
        /// 头像路径
        /// </summary>
        public virtual string HeadUrl { get; set; }

        /// <summary>
        /// 个性签名
        /// </summary>
        public virtual string Signature { get; set; }

        public virtual Gender Gender { get; set; }

        /// <summary>
        /// 自我介绍
        /// </summary>
        public virtual string Introduction { get; set; }

        public virtual string Address { get; set; }

        public virtual string MobilePhone { get; set; }

        /// <summary>
        /// 用户状态（封号、禁言之类）
        /// </summary>
        public virtual int StateID { get; set; }//

        /// <summary>
        /// 现有积分
        /// </summary>
        public virtual int Amount { get; set; }

        public virtual DateTime LastEditTime { get; set; }

        public virtual int LevelID { get; set; }//

        public virtual ISet<Group> Groups
        {
            get { return _groups; }
            set { _groups = value; }
        }

        public virtual ISet<Posts> Posts
        {
            get { return _posts; }
            set { _posts = value; }
        }

        public virtual ISet<Reply> Replys
        {
            get { return _reply; }
            set { _reply = value; }
        }
        #endregion

        #region 构造函数

        public User()
        {
            this._groups = new HashedSet<Group>();
            this._posts = new HashedSet<Posts>();
            this._reply = new HashedSet<Reply>();
        }

        #endregion

        #region 公有方法

        /// <summary>
        /// 发表一个帖子
        /// </summary>
        /// <param name="p"></param>
        public virtual void AddPost(Posts p)
        {
            this._posts.Add(p);
            p.PubUser = this;
        }

        /// <summary>
        /// 删除帖子
        /// </summary>
        /// <param name="p"></param>
        public virtual void DeletePost(Posts p)
        {
            if (this._posts.Contains(p))
            {
                this._posts.Remove(p);
            }
        }

        /// <summary>
        /// 更新帖子
        /// </summary>
        /// <param name="p"></param>
        public virtual void UpdatePost(Posts p)
        {
            var oldPosts = this._posts;
            if (this._posts.Contains(p))
            {
                oldPosts.Remove(p);
                oldPosts.Add(p);
            }
            this._posts = oldPosts;
        }

        /// <summary>
        /// 发表一个回复
        /// </summary>
        /// <param name="r"></param>
        public virtual void AddReply(Reply r)
        {
            this._reply.Add(r);
            r.ReplyUser = this;
        }

        #endregion
    }
}
